Skip to content

github-backup(clone_all): clear partial destinations and retry the clone (#3233) - #4332

Merged
dezren39 merged 2 commits into
mainfrom
queue/5682-3233-clone-all-partial
Nov 2, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/5682-3233-clone-all-partial

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #3233 (queue task 5682).

Problem

clone_all.py's clone_one only checked valid_mirror(dest) before cloning. A clone killed mid-flight (driver TIMEOUT=5400, interrupt, laptop sleep) leaves a partial destination that is not a valid mirror; git clone --mirror refuses it ("already exists and is not an empty directory") and nothing ever cleared it — the repo stayed unmirrored on every rerun until manual cleanup, and reconcile.py's clone pass inherited the wedge.

Change (infra/github-backup/bin/clone_all.py)

  • New clear_partial_dest(root, dest): removes a leftover partial destination, guarded to the driver-managed mirror path only — the destination must resolve to <root>/<owner>/<repo>.git exactly as mirror_path builds it. Anything outside that tree is left untouched and clone_one fails loudly naming the path, instead of the confusing git error.
  • An empty directory is not treated as partial (git clone accepts it); a valid mirror never reaches the helper (already-present behavior preserved).
  • The status record for the repo carries cleared_partial: true whenever a partial was cleared — on success, on clone failure, and on the TimeoutExpired path — so clone-status.jsonl distinguishes a cleared-partial retry from an ordinary failure.

Tests (infra/github-backup/tests/test_clone_all_partial.py)

Drives the real clone_all.main() against a temp backup root with a git-faithful fake git clone (refuses non-empty destinations, otherwise creates a real bare mirror; valid_mirror stays real):

  • partial destination → cleared, cloned, cleared_partial set — fails on the previous code (8 partial checks failed pre-fix), passes now
  • partial + clone failure / partial + timeout → fail records still carry cleared_partial
  • valid mirror → already-present, untouched, never re-cloned
  • absent destination and empty-dir destination → normal clone, no marker

Sibling suites on the laptop: test_drain_queue.py 54/54, test_inventory_owner.py 18/18, test_reconcile_retention.py 9/9.

Out of scope per the task packet: drain_queue.py ack behavior (#3219), inventory_owner null-owner handling (#3229), fetch_mirrors.py, ROADMAP files.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…one (#3233)

A clone killed mid-flight (driver timeout, interrupt, laptop sleep) left a non-empty destination that is not a valid mirror; git refused every rerun with already-exists and nothing cleared it, so the repo stayed unmirrored until manual cleanup.

clone_one now clears a partial destination before cloning (clear_partial_dest, guarded to the driver-managed <root>/<owner>/<repo>.git path only; anything outside it fails loudly instead of being removed) and stamps cleared_partial on the clone-status.jsonl record so a cleared-partial retry is distinguishable from an ordinary failure, including on the timeout path. Valid mirrors are untouched (already-present), and an empty directory is not treated as partial.

Regression tests (tests/test_clone_all_partial.py) drive the real clone_all.main() with a git-faithful fake clone: the 8 partial-destination checks fail on the previous code and pass now; valid-mirror, absent, and empty-dir controls pass throughout. Sibling suites still pass: drain_queue 54/54, inventory_owner 18/18, reconcile_retention 9/9.
@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 10:59
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4c624ade-8712-482c-9076-658172c33cc9
Commits

Reviewing files that changed from the base of the PR and between bd0465e and 7cf8578.

Files selected for processing: 2
  • infra/github-backup/bin/clone_all.py
  • infra/github-backup/tests/test_clone_all_partial.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T11:07:58.080055Z 7cf8578 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1ed3fa1db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread infra/github-backup/bin/clone_all.py Outdated
# clone below fails on 'already exists' forever. The status
# record carries cleared_partial so a cleared-partial retry is
# distinguishable from an ordinary failure in clone-status.jsonl.
cleared_partial = clear_partial_dest(root, dest)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve mirrors when Git inspection fails for policy reasons

If an intact backup has different ownership after a restore, valid_mirror() can return false because Git reports detected dubious ownership, not because the clone is partial. When the running user can remove that tree, this new unconditional cleanup deletes the entire existing backup before attempting a network clone. This was reproduced with a real bare repository whose directory ownership was changed; the legitimate safe.bareRepository=explicit setting also produces the same false-negative. Distinguish inspection or policy errors from confirmed partial destinations before deleting anything, otherwise a failed replacement clone leaves the user without their intact local backup.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7cf8578 — thank you, this was a real data-loss path.

clone_one now clears a destination only when dest_is_confirmed_partial() positively proves it is not a repository:

  • git answering rev-parse --is-bare-repository at all (rc 0) means a real repository lives there — preserved, whatever valid_mirror concluded;
  • a git failure other than "not a git repository" (dubious ownership, safe.bareRepository=explicit, any policy/inspection error) — preserved, with a loud fail record naming the path;
  • only "not a git repository" destinations and stray files at the mirror path are confirmed partial, and those are still cleared (driver-managed-tree guard unchanged) and retried.

Regression coverage added in test_clone_all_partial.py: a policy_error case (fake git refuses inspection of an intact mirror while valid_mirror is patched false) and a real-repo case (git opens the destination though valid_mirror says no) both assert the mirror is untouched, no clone is attempted, and no cleared_partial marker is written. 36/36 checks pass on the laptop.

…3233)

Codex P1 on PR #4332: valid_mirror() also returns false for intact mirrors when git refuses inspection for policy reasons (dubious ownership after a restore, safe.bareRepository=explicit) — the first cut would have deleted an intact backup and, if the replacement clone then failed, left no local copy at all.

clone_one now clears a destination only when dest_is_confirmed_partial proves it is not a repository: git answering rev-parse at all (rc 0) means a real repository lives there, and any git failure other than not-a-git-repository is an inspection/policy error. Both shapes are preserved with a loud fail record naming the path. Confirmed partials (not-a-repository, stray file) are still cleared and retried as before, still guarded to the driver-managed mirror tree.

Tests: new policy_error case (fake git refuses inspection of an intact mirror while valid_mirror is patched false) and real-repo case (git opens the destination though valid_mirror says no) both assert preservation, no clone attempted, no cleared_partial marker; stray-file case asserts clearing. 36/36 checks pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

github-backup(clone_all): a clone killed mid-flight leaves a partial destination every rerun rejects — the 'resumable' driver never resumes that repo

1 participant